from pymilvus import connections
from .doc import init_doc_collection, insert_doc_vectors, insert_doc_vector, search_doc_vectors
from .image import init_image_collection, insert_image_vectors, insert_image_vector, search_image_vectors

# 定义一个全局变量，标记Milvus是否已连接
_milvus_connected = False

# 定义确保Milvus连接的函数
def ensure_milvus_connection(host="localhost", port="19530", db_name="test"):
    global _milvus_connected
    if not _milvus_connected:
        # 连接到Milvus服务
        connections.connect(host=host, port=port, db_name=db_name)
        # 初始化文档向量集合
        init_doc_collection()
        # 初始化图片向量集合
        init_image_collection()
        # 设置连接标志为True,避免重复连接
        _milvus_connected = True

# 定义模块对外暴露的成员
__all__ = [
    ensure_milvus_connection
]